const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: {},
        invite: {},
        register: {},
        user: {},
        count:0,
        ruleShow:false,
        pageShow:false,
    },
    escape2Html: function (str) {
        var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
        return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; });
    },
    show() {
        this.setData({
            ruleShow:!this.data.ruleShow
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getData();
    },
    getData() {
        let _this = this;
        app.loading();
        app.HttpsRequest('share/index').then(ret => {
            if (ret) {
                wx.hideLoading();
                _this.setData({
                    page: ret.data.page,
                    invite: ret.data.invite,
                    register: ret.data.register,
                    user: ret.data.user, 
                    count: ret.data.count, 
                    pageShow: true, 
                })
            }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function(res) {
        let wechat = wx.getStorageSync('wechat');
        let user;
        if (wechat) {
            user = JSON.parse(wx.getStorageSync('wechat'))
        }
        return {
            title: user.nickName + '邀请您注册悠家会员',
            path: '/pages/index/index?referrer_id=' + this.data.user.account_id,
            success: (res) => {
                console.log(1);
                console.log(res);
            },
             fail: (err) => {
                console.log(err);
             }
        }
    },
    onShareTimeLine() {
        let wechat = wx.getStorageSync('wechat');
        let user;
        if (wechat) {
            user = JSON.parse(wx.getStorageSync('wechat'))
        }
        return {
            title: user.nickName + '邀请您注册悠家会员',
            query: '/pages/index/index?referrer_id=' + this.data.user.account_id,
            success: (res) => {
                console.log(res);
            }
        }
    }
})